package com.hrma.controller;

import com.github.pagehelper.Page;
import com.hrma.entity.*;
import com.hrma.services.RecruitScheduleService;
import com.hrma.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/recruitSchedule")
@Slf4j
public class RecruitScheduleController {
    @Autowired
    private final RecruitScheduleService recruitScheduleService;

    public RecruitScheduleController(RecruitScheduleService recruitScheduleService) {
        this.recruitScheduleService = recruitScheduleService;
    }

//    @PostMapping("/add")
//    public Result<RecruitSchedule> add(@RequestBody RecruitSchedule data) {
//        log.debug("收到add请求，请求参数：{}", data);
//        return Result.ok(recruitScheduleService.add(data));
//    }

    @PatchMapping("/delete")
    public Result<?> delete(@RequestBody RecruitScheduleVO data) {
        log.debug("收到delete请求，请求参数：{}", data);
        recruitScheduleService.delete(data);
        return Result.ok(null);
    }

    @PatchMapping("/update")
    public Result<?> update(@RequestBody RecruitScheduleVO data) {
        log.debug("收到update请求，请求参数：{}", data);
        recruitScheduleService.update(data);
        return Result.ok(null);
    }

    @GetMapping("/select")
    public Result<List<SelectResult>> select() {
        log.debug("收到select请求！");
        return Result.ok(recruitScheduleService.select());

    }

    @PostMapping("/list")
    public Result<ListWithCount<RecruitScheduleVO>> getList(@RequestBody RecruitScheduleDTO data) {
        log.debug("收到list请求，请求参数：{}", data);
        Page<RecruitScheduleVO> res = recruitScheduleService.getList(data);

        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @PostMapping("/hire")
    public Result<EmployeeFromRecruit> hire(@RequestBody EmployeeFromRecruit data) {
        log.debug("收到add请求，请求参数：{}", data);
        return Result.ok(recruitScheduleService.hire(data));
    }
}
